﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace CPPEI.Coolzon.UI.XProperty.Converters
{
    /// <summary>
    /// <TextAlign Value="Left"/>
    /// </summary>
    public class XTextAlignConverter : IPropertyValueConverter
    {
        public object Convert(ConvertContext context, Metadata.ValueNode valueNode)
        {
            string strAlign = valueNode.Attributes["Value"].ToUpper();
            if (strAlign == "LEFT")
            {
                return TextAlignment.Left;
            }
            else if (strAlign == "RIGHT")
            {
                return TextAlignment.Right;
            }
            else if (strAlign == "CENTER")
            {
                return TextAlignment.Center;
            }
            return TextAlignment.Justify;
        }

        public Metadata.ValueNode ConvertBack(ConvertContext context, object value)
        {
            Metadata.ValueNode valueNode = new Metadata.ValueNode("TextAlign");
            valueNode.Attributes = new Dictionary<string, string>();
            if ((TextAlignment)value == TextAlignment.Left)
            {
                valueNode.Attributes.Add("Value", "LEFT");
            }
            else if ((TextAlignment)value == TextAlignment.Right)
            {
                valueNode.Attributes.Add("Value", "RIGHT");
            }
            else if ((TextAlignment)value == TextAlignment.Center)
            {
                valueNode.Attributes.Add("Value", "CENTER");
            }
            else
            {
                valueNode.Attributes.Add("Value", "JUSTIFY");
            }
            return valueNode;
        }
    }
}
